module(..., package.seeall)

import("glutton.item", "Item")


Attribute = class("Attribute", Named)
function Attribute.__init(self, name)
	Named.__init(self, name)
	self.relation = {}
end

function Attribute.link(self, attr, value)
	self:_link(attr, value)
	attr:_link(self, value)
end
	
function Attribute._link(self, attr, value)
	self.relation[attr] = value
end

function Attribute.unlink(self, attr)
	self:_unlink(attr)
	attr:_unlink(self)
end

function Attribute._unlink(self, attr)
	self.relation[attr] = nil
end


Sweetness  = Attribute("sweetness")
Bitterness = Attribute("bitterness")
Saltiness  = Attribute("saltiness")
Sourness   = Attribute("sourness")
Hotness    = Attribute("hotness")
Coolness   = Attribute("coolness")

Sweetness.link(Bitterness, -1)
Saltiness.link(Sourness, -1)
Hotness.link(Coolness, -1)


Food = class("Food", Item)
Food.attributes = {Sweetness, Bitterness, Saltiness, Sourness, Hotness, Coolness}
-- Provide default values for food attributes
for _, attr in ipairs(Food.attrs) do
	Food[attr.name] = 0
end


Honey = class("Honey", Food)
Honey.sweetness = 90


ChiliPepper = class("Chili Pepper", Food)
ChiliPepper.hotness = 100


Mint = class("Mint", Food)
Mint.coolness = 100


function Stomach.add(self, food)
    for _, attr in ipairs(Food.basic_tastes) do
        self[attr] = combine_attribute(attr, self, food)
    end
    self.size = self.size + food.size
end
    
function combine_attribute(name, A, B)
    local ratio = A.size / (A.size + B.size)
    return A[name] * ratio + B[name] * (1 - ratio)
end

